package com.lz.sports.dialog

import android.app.Dialog
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.lz.comm.image.GlideApp
import com.lz.library.dialog.BaseDialogFragment
import com.lz.library.extension.dp2px
import com.lz.sports.R
import com.lz.sports.bean.Examinee
import com.lz.sports.databinding.DialogExamineeImgBinding

//图片显示
class ExamineeImgDialog : BaseDialogFragment<DialogExamineeImgBinding>() {

    companion object {
        fun show(activity: FragmentActivity, examinee: Examinee?): ExamineeImgDialog {
            val dialog = ExamineeImgDialog().also {
                it.arguments = Bundle().apply { putParcelable("examinee", examinee) }
            }
            dialog.setFrom(true)
            dialog.show(activity.supportFragmentManager)
            return dialog
        }

        fun show(fragment: Fragment, examinee: Examinee?): ExamineeImgDialog {
            val dialog = ExamineeImgDialog().also {
                it.arguments = Bundle().apply {
                    it.arguments = Bundle().apply { putParcelable("examinee", examinee) }
                }
            }
            dialog.show(fragment.childFragmentManager)
            return dialog
        }
    }

    override fun getLayoutRes(): Int = R.layout.dialog_examinee_img

    override fun initData(v: View, savedState: Bundle?) {
        val examinee = arguments?.getParcelable<Examinee>("examinee")
        if (examinee != null) {
            GlideApp.with(this).load(examinee.examPhotoFile()).into(binding.ivHead)
        }
    }

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = object : BaseDialog(requireContext()) {
        override fun initParams(params: WindowManager.LayoutParams) {
            params.width = 120f.dp2px()
            params.height = 160f.dp2px()
        }
    }
}